package com.huika.renrench.utils;

import sharesdk.cn.sharesdk.onekeyshare.MySharePopWindows;
import sharesdk.cn.sharesdk.onekeyshare.OnekeyShareTool;
import sharesdk.cn.sharesdk.onekeyshare.MySharePopWindows.GriViewOnImtermClick;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.tencent.qzone.QZone;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

import com.huika.lib.utils.StringTool;
import com.huika.renrench.R;
import com.huika.renrench.control.common.activity.MobileContactActivity;

public class ShareUtils implements GriViewOnImtermClick{
	
	private MySharePopWindows popWindows;// 分享
	private Context context;// 分享
	
	public void getShareUtils(View invite_friend_lin ,Context context) {
		this.context = context;
		initPopWindows();// 初始化分享
		popWindows.showPop(invite_friend_lin);
	}

	private void initPopWindows() {
		String[] title = new String[] { context.getString(R.string.wechat), context.getString(R.string.qq), context.getString(R.string.sinaweibo),context.getString(R.string.wechatmoments),context.getString(R.string.qzone) };
		String[] platform = new String[] { Wechat.NAME, QQ.NAME, SinaWeibo.NAME ,WechatMoments.NAME,QZone.NAME};
		Drawable[] resImg = new Drawable[] { context.getResources().getDrawable(R.drawable.pm_logo_wechat), context.getResources().getDrawable(R.drawable.pm_logo_qq),
				context.getResources().getDrawable(R.drawable.pm_logo_sinaweibo),context.getResources().getDrawable(R.drawable.pm_logo_wechatmoments),
				context.getResources().getDrawable(R.drawable.pm_logo_qzone)};
		popWindows = new MySharePopWindows(context, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, title, platform, resImg, this);
	}

	String product;

	@Override
	public void onGvOnItem(String arg0) {
		product = WebNetUtils.getWebUrl("12");
		if (StringTool.isEmpty(product)) {
			return;
		}
		if (arg0.equals("短信")) {
			Intent intent = new Intent();
			intent.putExtra(MobileContactActivity.SHARE_CONTENT, String.format(MobileContactActivity.SMS_PRE, "iphone6", "13655"));
			intent.setClass(context, MobileContactActivity.class);
			context.startActivity(intent);
		} else if (WechatMoments.NAME.equals(arg0)) {
			// 微信朋友圈
			ShareSDK.initSDK(context);

			// TODO
			String title = "推荐人人创给你--草根创业一站式服务平台";
			String shareStr = "选项目、学技术、选址、装修、资金周转、创业交流，想创业来人人创就够了！";// 分享内容
			String img = "http://image.app.renrench.com/rrc1/M00/00/2F/CqvBj1V5TTeAY7qIAAAOCW-7Z1M076.jpg";
			// String img = "";
			OnekeyShareTool.initShareInfo(context, title, product/*
																		 * UrlConstants
																		 * .
																		 * DOWNLOAD
																		 */, shareStr/* 分享内容 */, ""/* 商品的网页地址 */, product/* 商品的网页地址 */, img, "人人创", product, R.drawable.ic_launcher,
					true, arg0, null);
		}/*
		 * else if(QQ.NAME.equals(arg0)){ //QQ好友
		 * 
		 * }
		 */else {
			ShareSDK.initSDK(context);
			String title = "推荐人人创给你--草根创业一站式服务平台";
			String shareStr = "选项目、学技术、选址、装修、资金周转、创业交流，想创业来人人创就够了！";// 分享内容
			// if (shareStr.length() > 20) {
			// shareStr = shareStr.substring(0, 19);
			// }
			String img = "http://image.app.renrench.com/rrc1/M00/00/2F/CqvBj1V5TTeAY7qIAAAOCW-7Z1M076.jpg";
			// String img = "";
			String sinaUrl = "";
			if (SinaWeibo.NAME.equals(arg0)) {
				sinaUrl = product;
				if (shareStr.length()>140) {
					shareStr = shareStr.substring(0, 140);
				}
			}
			// double maxOtherPrice = 56.00;
			// shareStr = String.format(MobileContactActivity.SMS_PRE,
			// "iphone6", "13655");
			OnekeyShareTool.initShareInfo(context, title, product /*
																		 * UrlConstants
																		 * .
																		 * DOWNLOAD
																		 */, shareStr /* 分享内容 */, sinaUrl /* 商品的网页地址 */, product /* 商品的网页地址 */, img, "人人创", product,
					R.drawable.ic_launcher, true, arg0, null);
		}
	}
	
}
